SWEP.Spawnable			= true
SWEP.AdminSpawnable		= true

SWEP.ViewModel			= "models/weapons/v_pistol.mdl"
SWEP.WorldModel			= "models/weapons/w_pistol.mdl"

SWEP.Weight				= 5
SWEP.AutoSwitchTo		= false
SWEP.AutoSwitchFrom		= false

SWEP.Primary.Recoil			= 1
SWEP.Primary.Damage			= 0
SWEP.Primary.NumShots		= 1
SWEP.Primary.Cone			= 0.02
SWEP.Primary.ClipSize		= -1
SWEP.Primary.Delay			= 1.87
SWEP.Primary.DefaultClip	= -1
SWEP.Primary.Automatic		= true
SWEP.Primary.Ammo			= "none"

SWEP.Secondary.ClipSize		= -1
SWEP.Secondary.DefaultClip	= -1
SWEP.Secondary.Automatic	= false
SWEP.Secondary.Delay 		= 1.0
SWEP.Secondary.Ammo			= "none"


local ShootSound = Sound("crazy_ball_snd.mp3")

if ( SERVER ) then

	AddCSLuaFile( "shared.lua" )
	
	SWEP.HoldType			= "pistol"
	
end

if ( CLIENT ) then

	SWEP.PrintName			= "Crazy Pistol"			
	SWEP.Author				= "Zombie"
	SWEP.Slot				= 0
	SWEP.SlotPos			= 0
	SWEP.Contact			= ""
	SWEP.Purpose			= "WBgun"
	SWEP.Instructions		= "Leftclik:Shoot balls"
	
end

function SWEP:LaunchBall( force )
	if (!SERVER) then return end
	local RandAngles = Angle(math.random(0,360),math.random(0,360),math.random(0,360))
	local ply = self.Owner
	local bola = ents.Create("crazy_ball")
		bola:SetPos(ply:GetShootPos())
		bola:SetAngles( RandAngles )
		bola:Spawn()
		bola:Fire("Kill", "", 20)
		bola.iOwner = ply
		bola.iOwnerTeam = ply:Team()
		
	local bPhys = bola:GetPhysicsObject()
	local Force = ply:GetAimVector() * force
	bPhys:ApplyForceCenter(Force)
	self.Weapon:SetNextPrimaryFire(CurTime() + self.Primary.Delay)
end

function SWEP:PrimaryAttack( )
	self:LaunchBall( 900 )
	self.Weapon:EmitSound( ShootSound, 75, 110 )
	self.BaseClass.ShootEffects( self )
end

function SWEP:SecondaryAttack( )
	self.Owner:SetVelocity( self.Owner:GetForward() * -800 + Vector( 0, 0, 200 ) )
	self.BaseClass.ShootEffects( self )
	
	self:LaunchBall( 400 )
	self:LaunchBall( 400 )
	self:LaunchBall( 400 )
	self:LaunchBall( 400 )
	self:LaunchBall( 400 )
	self:LaunchBall( 400 )
	
	//tempo...
	self.Weapon:SetNextSecondaryFire(CurTime() + 4.2)
end
